home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / pbm3 / part1 next >
Encoding:
Internet Message Format  |  1989-02-03  |  48.0 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: jef@helios.ee.lbl.gov (Jef Poskanzer)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i041: pbm.shar1
  5. Message-ID: <8811010236.AA02692@helios.ee.lbl.gov>
  6. Date: 9 Nov 88 02:33:07 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: jef@helios.ee.lbl.gov (Jef Poskanzer)
  9. Lines: 1721
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 41
  13. Submitted-by: "Jef Poskanzer" <jef@helios.ee.lbl.gov>
  14. Archive-name: pbm3/Part1
  15.  
  16. #! /bin/sh
  17. # This is a shell archive, meaning:
  18. # 1. Remove everything above the #! /bin/sh line.
  19. # 2. Save the resulting text in a file.
  20. # 3. Execute the file with /bin/sh (not csh) to create the files:
  21. #    README
  22. #    FORMATS
  23. #    Makefile
  24. #    cbmtopbm.c
  25. #    cbmtopbm.1
  26. #    icontopbm.c
  27. #    icontopbm.1
  28. #    macptopbm.c
  29. #    macptopbm.1
  30. #    rasttopbm.c
  31. #    rasttopbm.1
  32. #    xbmtopbm.c
  33. #    xbmtopbm.1
  34. #    xwdtopbm.c
  35. # This archive created: Mon Oct 31 18:33:27 1988
  36. # By:    Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
  37. export PATH; PATH=/bin:$PATH
  38. echo shar: extracting "'README'" '(4090 characters)'
  39. if test -f 'README'
  40. then
  41.     echo shar: will not over-write existing file "'README'"
  42. else
  43. sed 's/^X//' << \SHAR_EOF > 'README'
  44. X                       Portable Bitmap Toolkit
  45. X                       Version of 31oct88
  46. X                    Previous distribution 31aug88
  47. X
  48. X
  49. XIncluded are a number of programs for converting various bitmap formats
  50. Xto and from a portable format; plus some tools for manipulating the
  51. Xportable bitmaps.
  52. X
  53. XChanges since the X.V11R3 distribution of 31aug88:
  54. X
  55. X    The cbm format has been revised to support run-length encoding.
  56. X    Pbmtops now does run-length encoding.
  57. X
  58. XMajor changes since the X.V11R2 distribution of 28mar88:
  59. X
  60. X    The pbm format now has a "magic number".
  61. X    New conversion filters: brushtopbm, giftopbm, pbmtolj, pbmtomacp,
  62. X      pbmtoxwd, and pbmtox10wd.
  63. X    Icontopbm converter has a better parser -- it knows to skip over
  64. X      any extraneous comments at the beginning of the icon file.
  65. X    Pbmtops generates a different PostScript wrapper program -- it should
  66. X      handle huge bitmaps better.
  67. X    Xwdtopbm now handles byte-swapping correctly.
  68. X    Pbmmake takes a flag to specify the color of the new bitmap.
  69. X    Pbmpaste now implements 'or', 'and', and 'xor' operations as well
  70. X      as the default 'replace'.
  71. X
  72. X
  73. XFiles in this distribution:
  74. X
  75. X    README        this
  76. X    FORMATS        descriptions of the various bitmap formats
  77. X    Makefile        guess
  78. X
  79. X    brushtopbm.c    convert from Xerox doodle brushes to portable bitmap
  80. X    cbmtopbm.c        convert from compact bitmap to portable bitmap
  81. X    giftopbm.c        convert from GIF to portable bitmap
  82. X    icontopbm.c        convert from Sun icon to portable bitmap
  83. X    macptopbm.c        convert from MacPaint to portable bitmap
  84. X    rasttopbm.c        convert from Sun raster to portable bitmap
  85. X    xbmtopbm.c        convert from X10 or X11 bitmap to portable bitmap
  86. X    xwdtopbm.c        convert from X10 or X11 window dump to portable bitmap
  87. X    xxxtopbm.c        convert from UNKNOWN BITMAP to portable bitmap
  88. X
  89. X    pbmtoascii.c    convert from portable bitmap to ASCII graphic form
  90. X    pbmtocbm.c        convert from portable bitmap to compact bitmap
  91. X    pbmtoicon.c        convert from portable bitmap to Sun icon
  92. X    pbmtolj.c        convert from portable bitmap to HP LaserJet
  93. X    pbmtomacp.c        convert from portable bitmap to MacPaint
  94. X    pbmtops.c        convert from portable bitmap to PostScript
  95. X    pbmtoptx.c        convert from portable bitmap to Printronix
  96. X    pbmtorast.c        convert from portable bitmap to Sun raster
  97. X    pbmtoxbm.c        convert from portable bitmap to X11 bitmap
  98. X    pbmtox10bm.c    convert from portable bitmap to X10 bitmap
  99. X    pbmtoxwd.c        convert from portable bitmap to X11 window dump
  100. X    pbmtox10wd.c    convert from portable bitmap to X10 window dump
  101. X
  102. X    pbmcatlr.c        concatenate portable bitmaps left to right
  103. X    pbmcattb.c        concatenate portable bitmaps top to bottom
  104. X    pbmcrop.c        crop a portable bitmap
  105. X    pbmcut.c        cut a rectangle out of a portable bitmap
  106. X    pbmenlarge.c    enlarge a portable bitmap N times
  107. X    pbmfliplr.c        flip a portable bitmap left for right
  108. X    pbmfliptb.c        flip a portable bitmap top for bottom
  109. X    pbminvert.c        invert a portable bitmap
  110. X    pbmmake.c        create a blank bitmap of a specified size
  111. X    pbmpaste.c        paste a rectangle into a portable bitmap
  112. X    pbmtrnspos.c    transpose a portable bitmap x for y
  113. X
  114. X    libpbm[1-5].c    a few utility routines
  115. X    pbm.h        header file for libpbm
  116. X    libpbm.h        internal header file for libpbm
  117. X    macp.h        definitions for MacPaint files
  118. X    x10wd.h        definitions for X10 window dumps
  119. X    x11wd.h        definitions for X11 window dumps
  120. X    bmaliases        csh script to make aliases for converting formats
  121. X    *.1            manual entries for all of the tools
  122. X    pbm.5        manual entry for the pbm format
  123. X    bitreverse.h    useful include file
  124. X
  125. X
  126. XUnpack the files, edit Makefile and change the options to suit,
  127. Xmake, and enjoy!  Note that if you're not on a Sun, you won't be
  128. Xable to compile rasttopbm and pbmtorast.
  129. X
  130. XI've tested this stuff under 4.2 BSD, 4.3 BSD, and System V rel 2,
  131. Xand on both Suns and Vaxen.  Nevertheless, I'm sure bugs remain.
  132. XFeedback is welcome - send bug reports, enhancements, checks, money
  133. Xorders, etc. to the addresses below.
  134. X
  135. X
  136. X    Jef Poskanzer
  137. X    jef@rtsg.ee.lbl.gov
  138. X    {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
  139. SHAR_EOF
  140. if test 4090 -ne "`wc -c < 'README'`"
  141. then
  142.     echo shar: error transmitting "'README'" '(should have been 4090 characters)'
  143. fi
  144. fi # end of overwriting check
  145. echo shar: extracting "'FORMATS'" '(3320 characters)'
  146. if test -f 'FORMATS'
  147. then
  148.     echo shar: will not over-write existing file "'FORMATS'"
  149. else
  150. sed 's/^X//' << \SHAR_EOF > 'FORMATS'
  151. XThe portable bitmap format is a lowest common denominator.
  152. X
  153. XFormats currently supported are:
  154. X
  155. X    X11 and X10 bitmaps
  156. X    X11 window dump files
  157. X    Sun icons
  158. X    Sun raster files
  159. X    MacPaint
  160. X    GIF
  161. X    PostScript
  162. X    Printronix printer graphics
  163. X    HP LaserJet
  164. X    "portable bitmap format"
  165. X    "compact bitmap format"
  166. X
  167. X
  168. XThe portable bitmap format is something I came up with while I was
  169. Xat Xerox.  It is a lowest common denominator.  It was originally
  170. Xdesigned to make it reasonable to mail bitmaps between different
  171. Xtypes of machines using the typical stupid network mailers we have
  172. Xtoday.  Now it serves as the common language for this family of
  173. Xbitmap conversion filters.  The definition is as follows:
  174. X
  175. X    - A "magic number" for identifying the file type.  A pbm file's
  176. X    magic number is the two characters "P1".
  177. X
  178. X    - Whitespace (blanks, TABs, CRs, LFs).
  179. X
  180. X    - A width, formatted as ASCII characters in decimal.
  181. X
  182. X    - Whitespace.
  183. X
  184. X    - A height, again in ASCII decimal.
  185. X
  186. X    - Whitespace.
  187. X
  188. X    - Width * height bits, each either '1' or '0', starting at the top-left
  189. X    corner of the bitmap, proceding in normal English reading order.
  190. X
  191. X    - The character '1' means black, '0' means white.
  192. X
  193. X    - Whitespace in the bits section is ignored.
  194. X
  195. X    - Characters from a "#" to the next end-of-line are ignored (comments).
  196. X
  197. X    - No line may be longer than 70 characters.
  198. X
  199. XHere is an example of a small bitmap in this format:
  200. X
  201. X    P1
  202. X    # feep.pbm
  203. X    24 7
  204. X    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  205. X    0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
  206. X    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
  207. X    0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
  208. X    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
  209. X    0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
  210. X    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  211. X
  212. XPrograms that read this format should be as lenient as possible,
  213. Xaccepting anything that looks remotely like a bitmap.  For instance,
  214. Xthe above example does not actually conform to the standard, since
  215. Xit has whitespace before the width; neverthless, it should be accepted.
  216. X
  217. X
  218. XThe compact bitmap format is the same basic idea as the portable
  219. Xformat, but it assumes the underlying filesystem can reliably store
  220. X8-bit bytes.  If you have the compress and zcat programs, you should
  221. Xnot bother with compact bitmaps -- all formats are about the same size
  222. Xafter being compressed.  Otherwise, compact bitmaps are probably the
  223. Xmost space-efficient format.  The definition:
  224. X
  225. X    - Two bytes of "magic number", which are always 0x2A 0x17.
  226. X
  227. X    - Two bytes representing the width.  The bytes are in "big-endian"
  228. X    order, i.e. the formula for the width is firstbyte * 256 + secondbyte.
  229. X
  230. X    - Two bytes representing the height, same order as above.
  231. X
  232. X    - The bits, in the same order as in the portable format: starting
  233. X    at the top-left, proceeding in normal English reading order.
  234. X    Within each byte, the most significant bit is used first, and so
  235. X    on down to the least significant bit.
  236. X
  237. X    - Nothing special happens at the end of a row -- no padding, not even
  238. X    to the end of the current byte.
  239. X    
  240. X    - A 1 bit means black, a 0 bit means white;
  241. X
  242. X    - All eight bits of each byte are used, except of course for the
  243. X    last byte, where there may be some extra bits.  These are ignored.
  244. SHAR_EOF
  245. if test 3320 -ne "`wc -c < 'FORMATS'`"
  246. then
  247.     echo shar: error transmitting "'FORMATS'" '(should have been 3320 characters)'
  248. fi
  249. fi # end of overwriting check
  250. echo shar: extracting "'Makefile'" '(5820 characters)'
  251. if test -f 'Makefile'
  252. then
  253.     echo shar: will not over-write existing file "'Makefile'"
  254. else
  255. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  256. X# Makefile for pbm tools.
  257. X#
  258. X# Copyright (C) 1988 by Jef Poskanzer.
  259. X#
  260. X# Permission to use, copy, modify, and distribute this software and its
  261. X# documentation for any purpose and without fee is hereby granted, provided
  262. X# that the above copyright notice appear in all copies and that both that
  263. X# copyright notice and this permission notice appear in supporting
  264. X# documentation.  This software is provided "as is" without express or
  265. X# implied warranty.
  266. X
  267. X
  268. X# Valid options:
  269. X#   OS_BSD      Set this if your system is BSD 4.2 or later.
  270. X#   OS_SYSV     Set this if your system is System V.
  271. XOPTIONS    =    -DOS_BSD
  272. X
  273. X
  274. XCC      =    cc
  275. XCFLAGS  =    -O $(OPTIONS)
  276. XLDFLAGS =    -s
  277. XLDLIBS =    libpbm.a
  278. X
  279. X.SUFFIXES:    .1 .5 .cat
  280. X.1.cat:
  281. X    nroff -h -man $< > $@
  282. X.5.cat:
  283. X    nroff -h -man $< > $@
  284. X
  285. Xall:        brushtopbm brushtopbm.cat cbmtopbm cbmtopbm.cat \
  286. X        giftopbm giftopbm.cat icontopbm icontopbm.cat \
  287. X        macptopbm macptopbm.cat pbm.cat pbmcatlr pbmcatlr.cat \
  288. X        pbmcattb pbmcattb.cat pbmcrop pbmcrop.cat \
  289. X        pbmcut pbmcut.cat pbmenlarge pbmenlarge.cat \
  290. X        pbmfliplr pbmfliplr.cat pbmfliptb pbmfliptb.cat \
  291. X        pbminvert pbminvert.cat pbmmake pbmmake.cat \
  292. X        pbmpaste pbmpaste.cat pbmtoascii pbmtoascii.cat \
  293. X        pbmtocbm pbmtocbm.cat pbmtoicon pbmtoicon.cat \
  294. X        pbmtolj pbmtolj.cat pbmtomacp pbmtomacp.cat \
  295. X        pbmtops pbmtops.cat pbmtoptx pbmtoptx.cat \
  296. X        pbmtorast pbmtorast.cat pbmtox10bm pbmtox10bm.cat \
  297. X        pbmtox10wd pbmtox10wd.cat pbmtoxbm pbmtoxbm.cat \
  298. X        pbmtoxwd pbmtoxwd.cat pbmtrnspos pbmtrnspos.cat \
  299. X        rasttopbm rasttopbm.cat xbmtopbm xbmtopbm.cat \
  300. X        xwdtopbm xwdtopbm.cat xxxtopbm xxxtopbm.cat
  301. X
  302. X# Rule for plain programs.
  303. Xbrushtopbm cbmtopbm giftopbm icontopbm macptopbm pbmcatlr pbmcattb \
  304. Xpbmcrop pbmcut pbmenlarge pbmfliplr pbmfliptb pbminvert pbmmake \
  305. Xpbmpaste pbmtoascii pbmtocbm pbmtoicon pbmtolj pbmtomacp pbmtops \
  306. Xpbmtoptx pbmtox10bm pbmtox10wd pbmtoxbm pbmtoxwd pbmtrnspos \
  307. Xxbmtopbm xwdtopbm xxxtopbm:    pbm.h libpbm.a
  308. X    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(LDLIBS)
  309. X
  310. X# Rule for pixrect-dependent programs.
  311. Xpbmtorast rasttopbm:    pbm.h libpbm.a
  312. X    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(LDLIBS) -lpixrect
  313. X
  314. X# And library.
  315. Xlibpbm.a:    libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o
  316. X    -rm libpbm.a
  317. X        ar rc libpbm.a libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o
  318. X    -ranlib libpbm.a
  319. X
  320. Xlibpbm1.o:    pbm.h libpbm.h libpbm1.c
  321. X    $(CC) $(CFLAGS) -c libpbm1.c
  322. Xlibpbm2.o:    pbm.h libpbm.h libpbm2.c
  323. X    $(CC) $(CFLAGS) -c libpbm2.c
  324. Xlibpbm3.o:    pbm.h libpbm.h libpbm3.c
  325. X    $(CC) $(CFLAGS) -c libpbm3.c
  326. Xlibpbm4.o:    pbm.h libpbm.h libpbm4.c
  327. X    $(CC) $(CFLAGS) -c libpbm4.c
  328. Xlibpbm5.o:    pbm.h libpbm.h libpbm5.c
  329. X    $(CC) $(CFLAGS) -c libpbm5.c
  330. X
  331. X# Other dependencies.
  332. Xbrushtopbm:    brushtopbm.c
  333. Xcbmtopbm:    cbmtopbm.c
  334. Xgiftopbm:    giftopbm.c
  335. Xicontopbm:    icontopbm.c
  336. Xmacptopbm:    macptopbm.c macp.h
  337. Xpbmcatlr:    pbmcatlr.c
  338. Xpbmcattb:    pbmcattb.c
  339. Xpbmcrop:    pbmcrop.c
  340. Xpbmcut:        pbmcut.c
  341. Xpbmenlarge:    pbmenlarge.c
  342. Xpbmfliplr:    pbmfliplr.c
  343. Xpbmfliptb:    pbmfliptb.c
  344. Xpbminvert:    pbminvert.c
  345. Xpbmmake:    pbmmake.c
  346. Xpbmpaste:    pbmpaste.c
  347. Xpbmtoascii:    pbmtoascii.c
  348. Xpbmtocbm:    pbmtocbm.c
  349. Xpbmtoicon:    pbmtoicon.c
  350. Xpbmtolj:    pbmtolj.c
  351. Xpbmtomacp:    pbmtomacp.c macp.h
  352. Xpbmtops:    pbmtops.c
  353. Xpbmtoptx:    pbmtoptx.c
  354. Xpbmtorast:    pbmtorast.c
  355. Xpbmtox10bm:    pbmtox10bm.c
  356. Xpbmtoxbm:    pbmtoxbm.c
  357. Xpbmtox10wd:    pbmtox10wd.c x10wd.h
  358. Xpbmtoxwd:    pbmtoxwd.c x11wd.h
  359. Xpbmtrnspos:    pbmtrnspos.c
  360. Xrasttopbm:    rasttopbm.c
  361. Xxbmtopbm:    xbmtopbm.c
  362. Xxwdtopbm:    xwdtopbm.c x11wd.h x10wd.h
  363. Xxxxtopbm:    xxxtopbm.c
  364. X
  365. Xclean:
  366. X    -rm -f *.o *.cat libpbm.a pbm.shar* core
  367. X    -rm -f brushtopbm cbmtopbm giftopbm icontopbm macptopbm
  368. X    -rm -f pbmcatlr pbmcattb pbmcrop pbmcut pbmenlarge
  369. X    -rm -f pbmfliplr pbmfliptb pbminvert pbmmake pbmpaste
  370. X    -rm -f pbmtoascii pbmtocbm pbmtoicon pbmtolj pbmtomacp
  371. X    -rm -f pbmtops pbmtoptx pbmtorast pbmtox10bm pbmtoxbm
  372. X    -rm -f pbmtox10wd pbmtoxwd pbmtrnspos rasttopbm
  373. X    -rm -f xbmtopbm xwdtopbm xxxtopbm
  374. X
  375. Xshar:        pbm.shar
  376. Xpbm.shar:    pbm.shar1 pbm.shar2 pbm.shar3 pbm.shar4 pbm.shar5
  377. X
  378. Xpbm.shar1:    README FORMATS Makefile cbmtopbm.c cbmtopbm.1 icontopbm.c \
  379. X        icontopbm.1 macptopbm.c macptopbm.1 rasttopbm.c \
  380. X        rasttopbm.1 xbmtopbm.c xbmtopbm.1 xwdtopbm.c
  381. X    shar -v -c -p X README FORMATS Makefile cbmtopbm.c cbmtopbm.1 icontopbm.c icontopbm.1 macptopbm.c macptopbm.1 rasttopbm.c rasttopbm.1 xbmtopbm.c xbmtopbm.1 xwdtopbm.c > $@
  382. X
  383. Xpbm.shar2:    xwdtopbm.1 pbmtocbm.c pbmtocbm.1 pbmtoicon.c pbmtoicon.1 \
  384. X        pbmtops.c pbmtops.1 pbmtoptx.c pbmtoptx.1 pbmtorast.c \
  385. X        pbmtorast.1 pbmtoxbm.c pbmtoxbm.1 pbmtox10bm.c pbmtox10bm.1 \
  386. X        pbmtoascii.c pbmtoascii.1 pbmcatlr.c pbmcatlr.1 pbmcattb.c \
  387. X        pbmcattb.1 pbmfliplr.c pbmfliplr.1
  388. X    shar -v -c -p X xwdtopbm.1 pbmtocbm.c pbmtocbm.1 pbmtoicon.c pbmtoicon.1 pbmtops.c pbmtops.1 pbmtoptx.c pbmtoptx.1 pbmtorast.c pbmtorast.1 pbmtoxbm.c pbmtoxbm.1 pbmtox10bm.c pbmtox10bm.1 pbmtoascii.c pbmtoascii.1 pbmcatlr.c pbmcatlr.1 pbmcattb.c pbmcattb.1 pbmfliplr.c pbmfliplr.1 > $@
  389. X
  390. Xpbm.shar3:    pbmfliptb.c pbmfliptb.1 pbminvert.c pbminvert.1 pbmcrop.c \
  391. X        pbmcrop.1 pbmtrnspos.c pbmtrnspos.1 pbmcut.c pbmcut.1 \
  392. X        pbmpaste.c pbmpaste.1 xxxtopbm.c xxxtopbm.1 pbmenlarge.c \
  393. X        pbmenlarge.1 pbmmake.c pbmmake.1 pbmtolj.c pbmtolj.1 \
  394. X        pbmtomacp.c
  395. X    shar -v -c -p X pbmfliptb.c pbmfliptb.1 pbminvert.c pbminvert.1 pbmcrop.c pbmcrop.1 pbmtrnspos.c pbmtrnspos.1 pbmcut.c pbmcut.1 pbmpaste.c pbmpaste.1 xxxtopbm.c xxxtopbm.1 pbmenlarge.c pbmenlarge.1 pbmmake.c pbmmake.1 pbmtolj.c pbmtolj.1 pbmtomacp.c > $@
  396. X
  397. Xpbm.shar4:    pbmtomacp.1 pbmtox10wd.c pbmtox10wd.1 pbmtoxwd.c pbmtoxwd.1 \
  398. X        brushtopbm.c brushtopbm.1 libpbm1.c libpbm2.c libpbm3.c \
  399. X        libpbm4.c libpbm5.c giftopbm.c giftopbm.1
  400. X    shar -v -c -p X pbmtomacp.1 pbmtox10wd.c pbmtox10wd.1 pbmtoxwd.c pbmtoxwd.1 brushtopbm.c brushtopbm.1 libpbm1.c libpbm2.c libpbm3.c libpbm4.c libpbm5.c giftopbm.c giftopbm.1 > $@
  401. X
  402. Xpbm.shar5:    pbm.h libpbm.h macp.h x10wd.h x11wd.h pbm.5 bmaliases \
  403. X        bitreverse.h
  404. X    shar -v -c -p X pbm.h libpbm.h macp.h x10wd.h x11wd.h pbm.5 bmaliases bitreverse.h > $@
  405. SHAR_EOF
  406. if test 5820 -ne "`wc -c < 'Makefile'`"
  407. then
  408.     echo shar: error transmitting "'Makefile'" '(should have been 5820 characters)'
  409. fi
  410. fi # end of overwriting check
  411. echo shar: extracting "'cbmtopbm.c'" '(1112 characters)'
  412. if test -f 'cbmtopbm.c'
  413. then
  414.     echo shar: will not over-write existing file "'cbmtopbm.c'"
  415. else
  416. sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.c'
  417. X/* cbmtopbm.c - read a compact bitmap and write a portable bitmap
  418. X**
  419. X** Copyright (C) 1988 by Jef Poskanzer.
  420. X**
  421. X** Permission to use, copy, modify, and distribute this software and its
  422. X** documentation for any purpose and without fee is hereby granted, provided
  423. X** that the above copyright notice appear in all copies and that both that
  424. X** copyright notice and this permission notice appear in supporting
  425. X** documentation.  This software is provided "as is" without express or
  426. X** implied warranty.
  427. X*/
  428. X
  429. X#include <stdio.h>
  430. X#include "pbm.h"
  431. X
  432. Xmain( argc, argv )
  433. Xint argc;
  434. Xchar *argv[];
  435. X    {
  436. X    FILE *ifd;
  437. X    bit **bits, getbit();
  438. X    int rows, cols, row, col;
  439. X
  440. X    if ( argc > 2 )
  441. X    {
  442. X    fprintf( stderr, "usage:  %s [cbmfile]\n", argv[0] );
  443. X    exit( 1 );
  444. X    }
  445. X
  446. X    if ( argc == 2 )
  447. X    {
  448. X        ifd = fopen( argv[1], "r" );
  449. X        if ( ifd == NULL )
  450. X        {
  451. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  452. X        exit( 1 );
  453. X        }
  454. X    }
  455. X    else
  456. X    ifd = stdin;
  457. X
  458. X    bits = pbm_readcbm( ifd, &cols, &rows );
  459. X
  460. X    if ( ifd != stdin )
  461. X    fclose( ifd );
  462. X    
  463. X    pbm_writepbm( stdout, bits, cols, rows );
  464. X
  465. X    exit( 0 );
  466. X    }
  467. SHAR_EOF
  468. if test 1112 -ne "`wc -c < 'cbmtopbm.c'`"
  469. then
  470.     echo shar: error transmitting "'cbmtopbm.c'" '(should have been 1112 characters)'
  471. fi
  472. fi # end of overwriting check
  473. echo shar: extracting "'cbmtopbm.1'" '(669 characters)'
  474. if test -f 'cbmtopbm.1'
  475. then
  476.     echo shar: will not over-write existing file "'cbmtopbm.1'"
  477. else
  478. sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.1'
  479. X.TH cbmtopbm 1 "31 August 1988"
  480. X.SH NAME
  481. Xcbmtopbm - convert compact bitmaps into portable bitmaps
  482. X.SH SYNOPSIS
  483. Xcbmtopbm [cbmfile]
  484. X.SH DESCRIPTION
  485. XReads a compact bitmap as input.
  486. XProduces a portable bitmap as output.
  487. X.SH "SEE ALSO"
  488. Xpbmtocbm(1), pbm(5)
  489. X.SH AUTHOR
  490. XCopyright (C) 1988 by Jef Poskanzer.
  491. X
  492. XPermission to use, copy, modify, and distribute this software and its
  493. Xdocumentation for any purpose and without fee is hereby granted, provided
  494. Xthat the above copyright notice appear in all copies and that both that
  495. Xcopyright notice and this permission notice appear in supporting
  496. Xdocumentation.  This software is provided "as is" without express or
  497. Ximplied warranty.
  498. SHAR_EOF
  499. if test 669 -ne "`wc -c < 'cbmtopbm.1'`"
  500. then
  501.     echo shar: error transmitting "'cbmtopbm.1'" '(should have been 669 characters)'
  502. fi
  503. fi # end of overwriting check
  504. echo shar: extracting "'icontopbm.c'" '(3806 characters)'
  505. if test -f 'icontopbm.c'
  506. then
  507.     echo shar: will not over-write existing file "'icontopbm.c'"
  508. else
  509. sed 's/^X//' << \SHAR_EOF > 'icontopbm.c'
  510. X/* icontopbm.c - read a Sun icon file and produce a portable bitmap
  511. X**
  512. X** Copyright (C) 1988 by Jef Poskanzer.
  513. X**
  514. X** Permission to use, copy, modify, and distribute this software and its
  515. X** documentation for any purpose and without fee is hereby granted, provided
  516. X** that the above copyright notice appear in all copies and that both that
  517. X** copyright notice and this permission notice appear in supporting
  518. X** documentation.  This software is provided "as is" without express or
  519. X** implied warranty.
  520. X*/
  521. X
  522. X#include <stdio.h>
  523. X#include <sys/types.h>
  524. X#include "pbm.h"
  525. X
  526. Xmain( argc, argv )
  527. Xint argc;
  528. Xchar *argv[];
  529. X    {
  530. X    FILE *ifd;
  531. X    bit **bits;
  532. X    int rows, cols, row, col, shortcount, mask;
  533. X    short *data;
  534. X
  535. X    if ( argc > 2 )
  536. X    {
  537. X    fprintf( stderr, "usage: %s [iconfile]\n", argv[0] );
  538. X    exit( 1 );
  539. X    }
  540. X
  541. X    if ( argc == 2 )
  542. X    {
  543. X    ifd = fopen( argv[1], "r" );
  544. X    if ( ifd == NULL )
  545. X        {
  546. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  547. X        exit( 1 );
  548. X        }
  549. X    }
  550. X    else
  551. X    ifd = stdin;
  552. X
  553. X    if ( ReadIconFile( ifd, &cols, &rows, &data ) < 0 )
  554. X    {
  555. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  556. X    exit( 1 );
  557. X    }
  558. X
  559. X    if ( ifd != stdin )
  560. X    fclose( ifd );
  561. X
  562. X    bits = pbm_allocarray( cols, rows );
  563. X
  564. X    for ( row = 0; row < rows; row++ )
  565. X    {
  566. X    shortcount = 0;
  567. X    mask = 0x8000;
  568. X    for ( col = 0; col < cols; col++ )
  569. X        {
  570. X        if ( shortcount >= 16 )
  571. X        {
  572. X        data++;
  573. X        shortcount = 0;
  574. X        mask = 0x8000;
  575. X        }
  576. X        bits[row][col] = ( ( *data & mask ) ? 1 : 0 );
  577. X        shortcount++;
  578. X        mask = mask >> 1;
  579. X        }
  580. X    data++;
  581. X    }
  582. X
  583. X    pbm_writepbm( stdout, bits, cols, rows );
  584. X
  585. X    exit( 0 );
  586. X    }
  587. X
  588. X
  589. X/* size in bytes of a bitmap */
  590. X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height))
  591. X
  592. Xint
  593. XReadIconFile( file, width, height, data )
  594. XFILE *file;
  595. Xint *width, *height;
  596. Xshort **data;
  597. X    {
  598. X    char variable[81], ch;
  599. X    int status, value, i, data_length, gotsome;
  600. X
  601. X    if ( file == NULL )
  602. X        return -1;
  603. X
  604. X    gotsome = 0;
  605. X    *width = *height = -1;
  606. X    for ( ; ; )
  607. X    {
  608. X    while ( ( ch = getc( file ) ) == ',' | ch == '\n' | ch == '\t' |
  609. X        ch == ' ' )
  610. X        ;
  611. X    for ( i = 0;
  612. X          ch != '=' & ch != ',' & ch != '\n' & ch != '\t' & ch != ' ';
  613. X          i++ )
  614. X        {
  615. X        variable[i] = ch;
  616. X        ch = getc( file );
  617. X        }
  618. X    variable[i] = '\0';
  619. X
  620. X    if ( strcmp( variable, "*/" ) == 0 & gotsome )
  621. X        break;
  622. X
  623. X    if ( fscanf( file, "%d", &value ) != 1 )
  624. X        continue;
  625. X
  626. X    if ( strcmp( variable, "Width" ) == 0 )
  627. X        {
  628. X        *width = value;
  629. X        gotsome = 1;
  630. X        }
  631. X    else if ( strcmp( variable, "Height" ) == 0 )
  632. X        {
  633. X            *height = value;
  634. X        gotsome = 1;
  635. X        }
  636. X    else if ( strcmp( variable, "Depth" ) == 0 )
  637. X            {
  638. X        if ( value != 1 )
  639. X        {
  640. X        fprintf( stderr, "Invalid depth.\n" );
  641. X        return -1;
  642. X        }
  643. X        gotsome = 1;
  644. X        }
  645. X    else if ( strcmp( variable, "Format_version" ) == 0 )
  646. X            {
  647. X        if ( value != 1 )
  648. X        {
  649. X        fprintf( stderr, "Invalid Format_version.\n" );
  650. X        return -1;
  651. X        }
  652. X        gotsome = 1;
  653. X        }
  654. X    else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 )
  655. X            {
  656. X        if ( value != 16 )
  657. X        {
  658. X        fprintf( stderr, "Invalid Valid_bits_per_item.\n" );
  659. X        return -1;
  660. X        }
  661. X        gotsome = 1;
  662. X        }
  663. X    }
  664. X
  665. X    if ( *width <= 0 )
  666. X    {
  667. X    fprintf( stderr, "Invalid width: %d.\n", *width );
  668. X    return -1;
  669. X    }
  670. X    
  671. X    if ( *height <= 0 )
  672. X    {
  673. X    fprintf( stderr, "Invalid height: %d.\n", *height );
  674. X    return -1;
  675. X    }
  676. X
  677. X    data_length = BitmapSize( *width, *height );
  678. X    *data = (short *) malloc( data_length );
  679. X    data_length /= sizeof( short );
  680. X    if ( *data == NULL )
  681. X        {
  682. X        return -1;
  683. X    }
  684. X    
  685. X    for ( i = 0 ; i < data_length; i++ )
  686. X    {
  687. X    if ( i == 0 )
  688. X        status = fscanf( file, " 0x%4hx", *data );
  689. X    else
  690. X        status = fscanf( file, ", 0x%4hx", *data + i );
  691. X    if ( status != 1 )
  692. X        {
  693. X        free( *data );
  694. X        fprintf( stderr, "Error 4 scanning bits item.\n" );
  695. X        return -1;
  696. X        }
  697. X        }
  698. X
  699. X    return 0;
  700. X    }
  701. SHAR_EOF
  702. if test 3806 -ne "`wc -c < 'icontopbm.c'`"
  703. then
  704.     echo shar: error transmitting "'icontopbm.c'" '(should have been 3806 characters)'
  705. fi
  706. fi # end of overwriting check
  707. echo shar: extracting "'icontopbm.1'" '(662 characters)'
  708. if test -f 'icontopbm.1'
  709. then
  710.     echo shar: will not over-write existing file "'icontopbm.1'"
  711. else
  712. sed 's/^X//' << \SHAR_EOF > 'icontopbm.1'
  713. X.TH icontopbm 1 "31 August 1988"
  714. X.SH NAME
  715. Xicontopbm - convert Sun icons into portable bitmaps
  716. X.SH SYNOPSIS
  717. Xicontopbm [iconfile]
  718. X.SH DESCRIPTION
  719. XReads a Sun icon as input.
  720. XProduces a portable bitmap as output.
  721. X.SH "SEE ALSO"
  722. Xpbmtoicon(1), pbm(5)
  723. X.SH AUTHOR
  724. XCopyright (C) 1988 by Jef Poskanzer.
  725. X
  726. XPermission to use, copy, modify, and distribute this software and its
  727. Xdocumentation for any purpose and without fee is hereby granted, provided
  728. Xthat the above copyright notice appear in all copies and that both that
  729. Xcopyright notice and this permission notice appear in supporting
  730. Xdocumentation.  This software is provided "as is" without express or
  731. Ximplied warranty.
  732. SHAR_EOF
  733. if test 662 -ne "`wc -c < 'icontopbm.1'`"
  734. then
  735.     echo shar: error transmitting "'icontopbm.1'" '(should have been 662 characters)'
  736. fi
  737. fi # end of overwriting check
  738. echo shar: extracting "'macptopbm.c'" '(2965 characters)'
  739. if test -f 'macptopbm.c'
  740. then
  741.     echo shar: will not over-write existing file "'macptopbm.c'"
  742. else
  743. sed 's/^X//' << \SHAR_EOF > 'macptopbm.c'
  744. X/* macptopbm.c - read a MacPaint file and produce a portable bitmap
  745. X**
  746. X** Copyright (C) 1988 by Jef Poskanzer.
  747. X**
  748. X** Permission to use, copy, modify, and distribute this software and its
  749. X** documentation for any purpose and without fee is hereby granted, provided
  750. X** that the above copyright notice appear in all copies and that both that
  751. X** copyright notice and this permission notice appear in supporting
  752. X** documentation.  This software is provided "as is" without express or
  753. X** implied warranty.
  754. X*/
  755. X
  756. X#include <stdio.h>
  757. X#include <sys/types.h>
  758. X#include "pbm.h"
  759. X#include "macp.h"
  760. X
  761. Xmain( argc, argv )
  762. Xint argc;
  763. Xchar *argv[];
  764. X    {
  765. X    FILE *ifd;
  766. X    unsigned char Pic[MAX_LINES][BYTES_WIDE];
  767. X    bit **bits;
  768. X    int scanLine, rows, cols, row, bcol, i;
  769. X
  770. X    if ( argc > 2 )
  771. X    {
  772. X    fprintf( stderr, "usage: %s [macpfile]\n", argv[0] );
  773. X    exit( 1 );
  774. X    }
  775. X
  776. X    if ( argc == 2 )
  777. X    {
  778. X    ifd = fopen( argv[1], "r" );
  779. X    if ( ifd == NULL )
  780. X        {
  781. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  782. X        exit( 1 );
  783. X        }
  784. X    }
  785. X    else
  786. X    ifd = stdin;
  787. X
  788. X    if ( ReadMacPaintFile( ifd, &scanLine, Pic ) < 0 )
  789. X    {
  790. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  791. X    exit( 1 );
  792. X    }
  793. X
  794. X    if ( ifd != stdin )
  795. X    fclose( ifd );
  796. X
  797. X    cols = BYTES_WIDE * 8;
  798. X    rows = scanLine;
  799. X    bits = pbm_allocarray( cols, rows );
  800. X
  801. X    for ( row = 0; row < rows; row++ )
  802. X    for ( bcol = 0; bcol < BYTES_WIDE; bcol++ )
  803. X        for ( i = 0; i < 8; i++ )
  804. X        bits[row][bcol * 8 + i] = ( (Pic[row][bcol] >> (7 - i)) & 1);
  805. X
  806. X    pbm_writepbm( stdout, bits, cols, rows );
  807. X
  808. X    exit( 0 );
  809. X    }
  810. X
  811. X/*
  812. X** Some of the following routine is:
  813. X**
  814. X**                Copyright 1987 by Patrick J. Naughton
  815. X**                         All Rights Reserved
  816. X** Permission to use, copy, modify, and distribute this software and its
  817. X** documentation for any purpose and without fee is hereby granted,
  818. X** provided that the above copyright notice appear in all copies and that
  819. X** both that copyright notice and this permission notice appear in
  820. X** supporting documentation.
  821. X*/
  822. X
  823. Xint
  824. XReadMacPaintFile( file, scanLineP, Pic )
  825. XFILE *file;
  826. Xint *scanLineP;
  827. Xunsigned char Pic[MAX_LINES][BYTES_WIDE];
  828. X    {
  829. X    unsigned int i, j, k;
  830. X    unsigned char ch;
  831. X
  832. X    /* Skip over the header. */
  833. X    for ( i = 0; i < HEADER_LENGTH; i++ )
  834. X    getc( file );
  835. X
  836. X    *scanLineP = 0;
  837. X    k = 0;
  838. X
  839. X    while ( *scanLineP < MAX_LINES )
  840. X    {
  841. X    ch = (unsigned char) getc( file );    /* Count byte */
  842. X    i = (unsigned int) ch;
  843. X    if ( ch < 0x80 )
  844. X        {    /* Unpack next (I+1) chars as is */
  845. X        for ( j = 0; j <= i; j++ )
  846. X        if ( *scanLineP < MAX_LINES )
  847. X            {
  848. X            Pic[*scanLineP][k++] = (unsigned char) getc( file );
  849. X            if ( ! (k %= BYTES_WIDE) )
  850. X            *scanLineP += 1;
  851. X            }
  852. X        }
  853. X    else
  854. X        {    /* Repeat next char (2's comp I) times */
  855. X        ch = getc( file );
  856. X        for ( j = 0; j <= 256 - i; j++ )
  857. X        if ( *scanLineP < MAX_LINES )
  858. X            {
  859. X            Pic[*scanLineP][k++] = (unsigned char) ch;
  860. X            if ( ! (k %= BYTES_WIDE) )
  861. X            *scanLineP += 1;
  862. X            }
  863. X        }
  864. X    }
  865. X
  866. X    return(0);
  867. X    }
  868. SHAR_EOF
  869. if test 2965 -ne "`wc -c < 'macptopbm.c'`"
  870. then
  871.     echo shar: error transmitting "'macptopbm.c'" '(should have been 2965 characters)'
  872. fi
  873. fi # end of overwriting check
  874. echo shar: extracting "'macptopbm.1'" '(1066 characters)'
  875. if test -f 'macptopbm.1'
  876. then
  877.     echo shar: will not over-write existing file "'macptopbm.1'"
  878. else
  879. sed 's/^X//' << \SHAR_EOF > 'macptopbm.1'
  880. X.TH macptopbm 1 "31 August 1988"
  881. X.SH NAME
  882. Xmacptopbm - convert MacPaint files into portable bitmaps
  883. X.SH SYNOPSIS
  884. Xmacptopbm [macpfile]
  885. X.SH DESCRIPTION
  886. XReads a MacPaint file as input.
  887. XProduces a portable bitmap as output.
  888. X.SH "SEE ALSO"
  889. Xpbmtomacp(1), pbm(5)
  890. X.SH AUTHOR
  891. XCopyright (C) 1988 by Jef Poskanzer.
  892. X
  893. XPermission to use, copy, modify, and distribute this software and its
  894. Xdocumentation for any purpose and without fee is hereby granted, provided
  895. Xthat the above copyright notice appear in all copies and that both that
  896. Xcopyright notice and this permission notice appear in supporting
  897. Xdocumentation.  This software is provided "as is" without express or
  898. Ximplied warranty.
  899. X
  900. XThe MacPaint-reading code is
  901. XCopyright (c) 1987 by Patrick J. Naughton
  902. X(naughton@wind.sun.com)
  903. X
  904. XPermission to use, copy, modify, and distribute this software and its
  905. Xdocumentation for any purpose and without fee is hereby granted,
  906. Xprovided that the above copyright notice appear in all copies and that
  907. Xboth that copyright notice and this permission notice appear in
  908. Xsupporting documentation. 
  909. SHAR_EOF
  910. if test 1066 -ne "`wc -c < 'macptopbm.1'`"
  911. then
  912.     echo shar: error transmitting "'macptopbm.1'" '(should have been 1066 characters)'
  913. fi
  914. fi # end of overwriting check
  915. echo shar: extracting "'rasttopbm.c'" '(3223 characters)'
  916. if test -f 'rasttopbm.c'
  917. then
  918.     echo shar: will not over-write existing file "'rasttopbm.c'"
  919. else
  920. sed 's/^X//' << \SHAR_EOF > 'rasttopbm.c'
  921. X/* rasttopbm.c - read a Sun raster file and produce a portable bitmap
  922. X**
  923. X** Copyright (C) 1988 by Jef Poskanzer.
  924. X**
  925. X** Permission to use, copy, modify, and distribute this software and its
  926. X** documentation for any purpose and without fee is hereby granted, provided
  927. X** that the above copyright notice appear in all copies and that both that
  928. X** copyright notice and this permission notice appear in supporting
  929. X** documentation.  This software is provided "as is" without express or
  930. X** implied warranty.
  931. X*/
  932. X
  933. X#include <stdio.h>
  934. X#include "pbm.h"
  935. X
  936. X/* Because of the following include, this program compiles only on Suns. */
  937. X#include <pixrect/pixrect_hs.h>
  938. X
  939. Xmain( argc, argv )
  940. Xint argc;
  941. Xchar *argv[];
  942. X    {
  943. X    FILE *ifd;
  944. X    bit **bits;
  945. X    int rows, cols, row, col, shortcount, mask;
  946. X    int linesize;
  947. X    short *data;
  948. X
  949. X    if ( argc > 2 )
  950. X    {
  951. X    fprintf( stderr, "usage: %s [rastfile]\n", argv[0] );
  952. X    exit( 1 );
  953. X    }
  954. X
  955. X    if ( argc == 2 )
  956. X    {
  957. X    ifd = fopen( argv[1], "r" );
  958. X    if ( ifd == NULL )
  959. X        {
  960. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  961. X        exit( 1 );
  962. X        }
  963. X    }
  964. X    else
  965. X    ifd = stdin;
  966. X
  967. X    if ( ReadRasterFile( ifd, &cols, &rows, &linesize, &data ) < 0 )
  968. X    {
  969. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  970. X    exit( 1 );
  971. X    }
  972. X
  973. X    if ( ifd != stdin )
  974. X    fclose( ifd );
  975. X
  976. X    bits = pbm_allocarray( cols, rows );
  977. X
  978. X    for ( row = 0; row < rows; row++ )
  979. X    {
  980. X    shortcount = 0;
  981. X    mask = 0x8000;
  982. X    for ( col = 0; col < cols; col++ )
  983. X        {
  984. X        if ( mask == 0 )
  985. X        {
  986. X        shortcount++;
  987. X        mask = 0x8000;
  988. X        }
  989. X        bits[row][col] = ( *(data + shortcount) & mask ) ? 1 : 0;
  990. X        mask = mask >> 1;
  991. X        }
  992. X    data += linesize / sizeof(short);
  993. X    }
  994. X
  995. X    pbm_writepbm( stdout, bits, cols, rows );
  996. X
  997. X    exit( 0 );
  998. X    }
  999. X
  1000. X
  1001. Xint
  1002. XReadRasterFile( file, width, height, linebytes, data )
  1003. XFILE *file;
  1004. Xint *width, *height;
  1005. Xint *linebytes;
  1006. Xshort **data;
  1007. X    {
  1008. X    struct rasterfile header;
  1009. X    struct pixrect *pr, *pr_load_image();
  1010. X    int status, firsttime, value, i, data_length;
  1011. X
  1012. X    if ( file == NULL )
  1013. X    return -1;
  1014. X
  1015. X    *width = *height = -1;
  1016. X
  1017. X
  1018. X    /* Get the raster file's header. */
  1019. X    if ( pr_load_header( file, &header ) != 0 )
  1020. X    {
  1021. X    fprintf( stderr, "Unable to read in raster file header.\n");
  1022. X    return -1;
  1023. X    }
  1024. X
  1025. X    /* PBM can only handle monochrome bitmaps. */
  1026. X    if ( header.ras_depth != 1 )
  1027. X    {
  1028. X    fprintf( stderr, "Invalid depth.\n" );
  1029. X    return -1;
  1030. X    }
  1031. X
  1032. X    *width = header.ras_width;
  1033. X    *height = header.ras_height;
  1034. X    if ( *width <= 0 )
  1035. X    {
  1036. X    fprintf( stderr, "Invalid width: %d.\n", *width );
  1037. X    return -1;
  1038. X    }
  1039. X    
  1040. X    if ( *height <= 0 )
  1041. X    {
  1042. X    fprintf( stderr, "Invalid height: %d.\n", *height );
  1043. X    return -1;
  1044. X    }
  1045. X
  1046. X    /* If there is a color map, skip over it. */
  1047. X    if ( header.ras_maptype != RMT_NONE && header.ras_maplength != 0 )
  1048. X    {
  1049. X    if (pr_load_colormap(file, &header, NULL) != 0)
  1050. X        {
  1051. X        fprintf( stderr, "Unable to skip colormap data.\n");
  1052. X        return -1;
  1053. X        }
  1054. X    }
  1055. X
  1056. X    /* Now load the data.  The pixrect returned is a memory pixrect. */
  1057. X    if ( (pr = pr_load_image(file, &header, NULL)) == NULL )
  1058. X    {
  1059. X    fprintf(
  1060. X        stderr, "Unable to read in the image from the raster file.\n");
  1061. X    return -1;
  1062. X    }
  1063. X
  1064. X    *linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
  1065. X    *data = ((struct mpr_data *)pr->pr_data)->md_image;
  1066. X
  1067. X    return 0;
  1068. X    }
  1069. SHAR_EOF
  1070. if test 3223 -ne "`wc -c < 'rasttopbm.c'`"
  1071. then
  1072.     echo shar: error transmitting "'rasttopbm.c'" '(should have been 3223 characters)'
  1073. fi
  1074. fi # end of overwriting check
  1075. echo shar: extracting "'rasttopbm.1'" '(1052 characters)'
  1076. if test -f 'rasttopbm.1'
  1077. then
  1078.     echo shar: will not over-write existing file "'rasttopbm.1'"
  1079. else
  1080. sed 's/^X//' << \SHAR_EOF > 'rasttopbm.1'
  1081. X.TH rasttopbm 1 "31 August 1988"
  1082. X.SH NAME
  1083. Xrasttopbm - convert Sun rasters into portable bitmaps
  1084. X.SH SYNOPSIS
  1085. Xrasttopbm [rastfile]
  1086. X.SH DESCRIPTION
  1087. XReads a Sun raster as input.
  1088. XProduces a portable bitmap as output.
  1089. XNOTE: since it uses Sun-specific include files, pbmtorast will compile
  1090. Xonly on Suns.
  1091. X.LP
  1092. XUsing this program you can convert anything you can see on a Sun screen
  1093. Xinto a pbm bitmap.
  1094. XJust display whatever you're interested in, do a screendump, run it through
  1095. Xrasfilter8to1 if you're on a color Sun, run it through rasttopbm, and then
  1096. Xuse pbmcut to select the part you want.
  1097. X.SH "SEE ALSO"
  1098. Xpbmtorast(1), pbm(5)
  1099. X.SH AUTHOR
  1100. XBarry Klawans
  1101. X
  1102. XCopyright (C) 1988 by Jef Poskanzer.
  1103. X
  1104. XPermission to use, copy, modify, and distribute this software and its
  1105. Xdocumentation for any purpose and without fee is hereby granted, provided
  1106. Xthat the above copyright notice appear in all copies and that both that
  1107. Xcopyright notice and this permission notice appear in supporting
  1108. Xdocumentation.  This software is provided "as is" without express or
  1109. Ximplied warranty.
  1110. SHAR_EOF
  1111. if test 1052 -ne "`wc -c < 'rasttopbm.1'`"
  1112. then
  1113.     echo shar: error transmitting "'rasttopbm.1'" '(should have been 1052 characters)'
  1114. fi
  1115. fi # end of overwriting check
  1116. echo shar: extracting "'xbmtopbm.c'" '(4098 characters)'
  1117. if test -f 'xbmtopbm.c'
  1118. then
  1119.     echo shar: will not over-write existing file "'xbmtopbm.c'"
  1120. else
  1121. sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.c'
  1122. X/* xbmtopbm.c - read an X bitmap file and produce a portable bitmap
  1123. X**
  1124. X** Copyright (C) 1988 by Jef Poskanzer.
  1125. X**
  1126. X** Permission to use, copy, modify, and distribute this software and its
  1127. X** documentation for any purpose and without fee is hereby granted, provided
  1128. X** that the above copyright notice appear in all copies and that both that
  1129. X** copyright notice and this permission notice appear in supporting
  1130. X** documentation.  This software is provided "as is" without express or
  1131. X** implied warranty.
  1132. X*/
  1133. X
  1134. X#include <stdio.h>
  1135. X#include <sys/types.h>
  1136. X#include "pbm.h"
  1137. X
  1138. Xmain( argc, argv )
  1139. Xint argc;
  1140. Xchar *argv[];
  1141. X    {
  1142. X    FILE *ifd;
  1143. X    bit **bits;
  1144. X    int rows, cols, row, col, charcount;
  1145. X    char *data, mask;
  1146. X
  1147. X    if ( argc > 2 )
  1148. X    {
  1149. X    fprintf( stderr, "usage: %s [bitmapfile]\n", argv[0] );
  1150. X    exit( 1 );
  1151. X    }
  1152. X    
  1153. X    if ( argc == 2 )
  1154. X    {
  1155. X    ifd = fopen( argv[1], "r" );
  1156. X    if ( ifd == NULL )
  1157. X        {
  1158. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1159. X        exit( 1 );
  1160. X        }
  1161. X    }
  1162. X    else
  1163. X    ifd = stdin;
  1164. X
  1165. X    if ( ReadBitmapFile( ifd, &cols, &rows, &data ) < 0 )
  1166. X    {
  1167. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  1168. X    exit( 1 );
  1169. X    }
  1170. X
  1171. X    if ( ifd != stdin )
  1172. X    fclose( ifd );
  1173. X
  1174. X    bits = pbm_allocarray( cols, rows );
  1175. X
  1176. X    for ( row = 0; row < rows; row++ )
  1177. X    {
  1178. X    charcount = 0;
  1179. X    mask = 1;
  1180. X    for ( col = 0; col < cols; col++ )
  1181. X        {
  1182. X        if ( charcount >= 8 )
  1183. X        {
  1184. X        data++;
  1185. X        charcount = 0;
  1186. X        mask = 1;
  1187. X        }
  1188. X        bits[row][col] = ( *data & mask ) ? 1 : 0;
  1189. X        charcount++;
  1190. X        mask = mask << 1;
  1191. X        }
  1192. X    data++;
  1193. X    }
  1194. X
  1195. X    pbm_writepbm( stdout, bits, cols, rows );
  1196. X
  1197. X    exit( 0 );
  1198. X    }
  1199. X
  1200. X
  1201. X#ifdef    OS_SYSV
  1202. X#include <string.h>
  1203. X#else    OS_SYSV
  1204. X#include <strings.h>
  1205. X#endif    OS_SYSV
  1206. X
  1207. X#define MAX_LINE 200
  1208. X
  1209. Xint
  1210. XReadBitmapFile( stream, widthP, heightP, dataP )
  1211. XFILE *stream;
  1212. Xint *widthP, *heightP;
  1213. Xchar **dataP;
  1214. X    {
  1215. X    char line[MAX_LINE], name_and_type[MAX_LINE];
  1216. X    char *ptr, *t;
  1217. X    int bytes, bytes_per_line, value, version10p, raster_length, padding;
  1218. X
  1219. X    *widthP = *heightP = -1;
  1220. X
  1221. X    for ( ; ; )
  1222. X    {
  1223. X    if ( ! fgets( line, MAX_LINE, stream ) )
  1224. X        break;
  1225. X    if ( strlen( line ) == MAX_LINE - 1 )
  1226. X        {
  1227. X        fprintf( stderr, "Line too long.\n" );
  1228. X        return -1;
  1229. X        }
  1230. X
  1231. X    if (sscanf(line, "#define %s %d", name_and_type, &value) == 2)
  1232. X        {
  1233. X#ifdef    OS_SYSV
  1234. X        if ( ! (t = strrchr( name_and_type, '_' )) )
  1235. X#else    OS_SYSV
  1236. X        if ( ! (t = rindex( name_and_type, '_' )) )
  1237. X#endif    OS_SYSV
  1238. X        t = name_and_type;
  1239. X        else
  1240. X        t++;
  1241. X        if ( ! strcmp( "width", t ) )
  1242. X        *widthP = value;
  1243. X        if ( ! strcmp( "height", t ) )
  1244. X        *heightP = value;
  1245. X        continue;
  1246. X        }
  1247. X    
  1248. X    if ( sscanf( line, "static short %s = {", name_and_type ) == 1 )
  1249. X        {
  1250. X        version10p = 1;
  1251. X        break;
  1252. X        }
  1253. X    else if ( sscanf( line, "static char %s = {", name_and_type ) == 1 )
  1254. X        {
  1255. X        version10p = 0;
  1256. X        break;
  1257. X        }
  1258. X    else
  1259. X        continue;
  1260. X    }
  1261. X#ifdef    OS_SYSV
  1262. X    if ( ! (t = strrchr( name_and_type, '_' )) )
  1263. X#else    OS_SYSV
  1264. X    if ( ! (t = rindex( name_and_type, '_' )) )
  1265. X#endif    OS_SYSV
  1266. X    t = name_and_type;
  1267. X    else
  1268. X    t++;
  1269. X    
  1270. X    if ( *widthP == -1 )
  1271. X    {
  1272. X    fprintf( stderr, "Invalid width.\n" );
  1273. X    return -1;
  1274. X    }
  1275. X    if ( *heightP == -1 )
  1276. X    {
  1277. X    fprintf( stderr, "Invalid height.\n" );
  1278. X    return -1;
  1279. X    }
  1280. X
  1281. X    padding = 0;
  1282. X    if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10p )
  1283. X    padding = 1;
  1284. X
  1285. X    bytes_per_line = (*widthP+7)/8 + padding;
  1286. X    
  1287. X    raster_length =  bytes_per_line * *heightP;
  1288. X    *dataP = (char *) malloc( raster_length );
  1289. X    if ( ! *dataP )
  1290. X    {
  1291. X    fprintf( stderr, "Not enough memory.\n" );
  1292. X    return -1;
  1293. X    }
  1294. X
  1295. X    if ( version10p )
  1296. X    for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 )
  1297. X        {
  1298. X        if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
  1299. X        {
  1300. X        fprintf( stderr, "Error scanning bits item.\n" );
  1301. X        return -1;
  1302. X        }
  1303. X        *(ptr++) = value & 0xff;
  1304. X        if ( (! padding) || ((bytes+2) % bytes_per_line) )
  1305. X        *(ptr++) = value >> 8;
  1306. X        }
  1307. X    else
  1308. X        for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes++ )
  1309. X        {
  1310. X        if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
  1311. X            {
  1312. X            fprintf( stderr, "Error scanning bits item.\n" );
  1313. X            return -1;
  1314. X            }
  1315. X        *(ptr++) = value;
  1316. X        }
  1317. X
  1318. X    return 0;
  1319. X    }
  1320. SHAR_EOF
  1321. if test 4098 -ne "`wc -c < 'xbmtopbm.c'`"
  1322. then
  1323.     echo shar: error transmitting "'xbmtopbm.c'" '(should have been 4098 characters)'
  1324. fi
  1325. fi # end of overwriting check
  1326. echo shar: extracting "'xbmtopbm.1'" '(695 characters)'
  1327. if test -f 'xbmtopbm.1'
  1328. then
  1329.     echo shar: will not over-write existing file "'xbmtopbm.1'"
  1330. else
  1331. sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.1'
  1332. X.TH xbmtopbm 1 "31 August 1988"
  1333. X.SH NAME
  1334. Xxbmtopbm - convert X11 and X10 bitmaps into portable bitmaps
  1335. X.SH SYNOPSIS
  1336. Xxbmtopbm [bitmapfile]
  1337. X.SH DESCRIPTION
  1338. XReads an X11 or X10 bitmap as input.
  1339. XProduces a portable bitmap as output.
  1340. X.SH "SEE ALSO"
  1341. Xpbmtoxbm(1), pbmtox10bm(1), pbm(5)
  1342. X.SH AUTHOR
  1343. XCopyright (C) 1988 by Jef Poskanzer.
  1344. X
  1345. XPermission to use, copy, modify, and distribute this software and its
  1346. Xdocumentation for any purpose and without fee is hereby granted, provided
  1347. Xthat the above copyright notice appear in all copies and that both that
  1348. Xcopyright notice and this permission notice appear in supporting
  1349. Xdocumentation.  This software is provided "as is" without express or
  1350. Ximplied warranty.
  1351. SHAR_EOF
  1352. if test 695 -ne "`wc -c < 'xbmtopbm.1'`"
  1353. then
  1354.     echo shar: error transmitting "'xbmtopbm.1'" '(should have been 695 characters)'
  1355. fi
  1356. fi # end of overwriting check
  1357. echo shar: extracting "'xwdtopbm.c'" '(8899 characters)'
  1358. if test -f 'xwdtopbm.c'
  1359. then
  1360.     echo shar: will not over-write existing file "'xwdtopbm.c'"
  1361. else
  1362. sed 's/^X//' << \SHAR_EOF > 'xwdtopbm.c'
  1363. X/* xwdtopbm.c - read an X11 or X10 window dump file and write a portable bitmap
  1364. X**
  1365. X** Copyright (C) 1988 by Jef Poskanzer.
  1366. X**
  1367. X** Permission to use, copy, modify, and distribute this software and its
  1368. X** documentation for any purpose and without fee is hereby granted, provided
  1369. X** that the above copyright notice appear in all copies and that both that
  1370. X** copyright notice and this permission notice appear in supporting
  1371. X** documentation.  This software is provided "as is" without express or
  1372. X** implied warranty.
  1373. X*/
  1374. X
  1375. X#include <stdio.h>
  1376. X#include "pbm.h"
  1377. X#include "x10wd.h"
  1378. X#include "x11wd.h"
  1379. X
  1380. Xmain( argc, argv )
  1381. Xint argc;
  1382. Xchar *argv[];
  1383. X    {
  1384. X    FILE *ifd;
  1385. X    bit **bits, getbit();
  1386. X    int rows, cols, padright, row, col;
  1387. X
  1388. X    if ( argc > 2 )
  1389. X    {
  1390. X    fprintf( stderr, "usage:  %s [xwdfile]\n", argv[0] );
  1391. X    exit( 1 );
  1392. X    }
  1393. X
  1394. X    if ( argc == 2 )
  1395. X    {
  1396. X        ifd = fopen( argv[1], "r" );
  1397. X        if ( ifd == NULL )
  1398. X        {
  1399. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1400. X        exit( 1 );
  1401. X        }
  1402. X    }
  1403. X    else
  1404. X    ifd = stdin;
  1405. X
  1406. X    getinit( ifd, &cols, &rows, &padright );
  1407. X
  1408. X    bits = pbm_allocarray( cols, rows );
  1409. X
  1410. X    for ( row = 0; row < rows; row++ )
  1411. X    {
  1412. X        for ( col = 0; col < cols; col++ )
  1413. X        bits[row][col] = getbit( ifd );
  1414. X        for ( col = 0; col < padright; col++ )
  1415. X        (void) getbit( ifd );
  1416. X    }
  1417. X
  1418. X    if ( ifd != stdin )
  1419. X    fclose( ifd );
  1420. X    
  1421. X    pbm_writepbm( stdout, bits, cols, rows );
  1422. X
  1423. X    exit( 0 );
  1424. X    }
  1425. X
  1426. X
  1427. Xchar buf[4];
  1428. Xchar *byteP;
  1429. Xshort *shortP;
  1430. Xlong *longP;
  1431. Xint bits_per_item, bits_used, bit_shift, bit_order, bit_invert, byte_swap;
  1432. X
  1433. Xshort bs_short();
  1434. Xint bs_int();
  1435. Xlong bs_long();
  1436. X
  1437. X
  1438. Xgetinit( file, colP, rowP, padrightP )
  1439. XFILE *file;
  1440. Xint *colP, *rowP, *padrightP;
  1441. X    {
  1442. X    /* Assume X11 headers are larger than X10 ones. */
  1443. X    unsigned char header[sizeof(X11WDFileHeader)];
  1444. X    X10WDFileHeader *h10P;
  1445. X    X11WDFileHeader *h11P;
  1446. X    char junk[10000];
  1447. X    int i;
  1448. X
  1449. X    h10P = (X10WDFileHeader *) header;
  1450. X    h11P = (X11WDFileHeader *) header;
  1451. X
  1452. X    if ( sizeof(*h10P) > sizeof(*h11P) )
  1453. X    {
  1454. X    fprintf( stderr, "ARGH!  On this machine, X10 headers are larger than X11 headers!\n" );
  1455. X    fprintf( stderr, "You will have to re-write xwdtopbm.\n" );
  1456. X    exit( 1 );
  1457. X    }
  1458. X
  1459. X    /* Read an X10 header. */
  1460. X    if ( fread( &header[0], sizeof(*h10P), 1, file ) != 1 )
  1461. X    {
  1462. X    fprintf( stderr, "Couldn't read XWD file header.\n" );
  1463. X    exit( 1 );
  1464. X    }
  1465. X
  1466. X    if ( h10P->file_version == X10WD_FILE_VERSION ||
  1467. X     bs_int( h10P->file_version ) == X10WD_FILE_VERSION )
  1468. X    {
  1469. X    if ( h10P->file_version != X10WD_FILE_VERSION )
  1470. X        {
  1471. X        byte_swap = 1;
  1472. X        h10P->header_size = bs_int( h10P->header_size );
  1473. X        h10P->file_version = bs_int( h10P->file_version );
  1474. X        h10P->display_type = bs_int( h10P->display_type );
  1475. X        h10P->display_planes = bs_int( h10P->display_planes );
  1476. X        h10P->pixmap_format = bs_int( h10P->pixmap_format );
  1477. X        h10P->pixmap_width = bs_int( h10P->pixmap_width );
  1478. X        h10P->pixmap_height = bs_int( h10P->pixmap_height );
  1479. X        h10P->window_width = bs_short( h10P->window_width );
  1480. X        h10P->window_height = bs_short( h10P->window_height );
  1481. X        h10P->window_x = bs_short( h10P->window_x );
  1482. X        h10P->window_y = bs_short( h10P->window_y );
  1483. X        h10P->window_bdrwidth = bs_short( h10P->window_bdrwidth );
  1484. X        h10P->window_ncolors = bs_short( h10P->window_ncolors );
  1485. X        }
  1486. X    if ( fread( junk, h10P->header_size - sizeof(*h10P), 1, file ) != 1 )
  1487. X        {
  1488. X        fprintf( stderr, "Couldn't read rest of X10 XWD file header.\n" );
  1489. X        exit( 1 );
  1490. X        }
  1491. X    if ( fread( junk, sizeof(X10Color), h10P->window_ncolors, file ) !=
  1492. X         h10P->window_ncolors )
  1493. X        {
  1494. X        fprintf( stderr, "Couldn't read X10 XWD colormap.\n" );
  1495. X        exit( 1 );
  1496. X        }
  1497. X
  1498. X    /* Check whether we can handle this dump. */
  1499. X    if ( h10P->window_ncolors != 0 )
  1500. X        {
  1501. X        fprintf( stderr, "Can't handle X10 window_ncolors != 0.\n" );
  1502. X        exit( 1 );
  1503. X        }
  1504. X    if ( h10P->pixmap_format != XYFormat )
  1505. X        {
  1506. X        fprintf( stderr, "Can't handle X10 pixmap_format %d.\n",
  1507. X             h10P->pixmap_format );
  1508. X        exit( 1 );
  1509. X        }
  1510. X
  1511. X    *colP = h10P->pixmap_width;
  1512. X    *rowP = h10P->pixmap_height;
  1513. X    *padrightP =
  1514. X        ( ( h10P->pixmap_width + 15 ) / 16 ) * 16 - h10P->pixmap_width;
  1515. X    bits_per_item = 16;
  1516. X    bits_used = bits_per_item;
  1517. X    bit_order = LSBFirst;
  1518. X    bit_invert = 1;
  1519. X    }
  1520. X    else
  1521. X    {
  1522. X    if ( h11P->file_version == X11WD_FILE_VERSION ||
  1523. X         bs_long( h11P->file_version ) == X11WD_FILE_VERSION )
  1524. X        {
  1525. X        if ( fread( &header[sizeof(*h10P)], sizeof(*h11P) - sizeof(*h10P), 1, file ) != 1 )
  1526. X        {
  1527. X        fprintf( stderr, "Couldn't read X11 XWD file header.\n" );
  1528. X        exit( 1 );
  1529. X        }
  1530. X        if ( h11P->file_version != X11WD_FILE_VERSION )
  1531. X        {
  1532. X        byte_swap = 1;
  1533. X        h11P->header_size = bs_long( h11P->header_size );
  1534. X        h11P->file_version = bs_long( h11P->file_version );
  1535. X        h11P->pixmap_format = bs_long( h11P->pixmap_format );
  1536. X        h11P->pixmap_depth = bs_long( h11P->pixmap_depth );
  1537. X        h11P->pixmap_width = bs_long( h11P->pixmap_width );
  1538. X        h11P->pixmap_height = bs_long( h11P->pixmap_height );
  1539. X        h11P->xoffset = bs_long( h11P->xoffset );
  1540. X        h11P->byte_order = bs_long( h11P->byte_order );
  1541. X        h11P->bitmap_unit = bs_long( h11P->bitmap_unit );
  1542. X        h11P->bitmap_bit_order = bs_long( h11P->bitmap_bit_order );
  1543. X        h11P->bitmap_pad = bs_long( h11P->bitmap_pad );
  1544. X        h11P->bits_per_pixel = bs_long( h11P->bits_per_pixel );
  1545. X        h11P->bytes_per_line = bs_long( h11P->bytes_per_line );
  1546. X        h11P->visual_class = bs_long( h11P->visual_class );
  1547. X        h11P->red_mask = bs_long( h11P->red_mask );
  1548. X        h11P->green_mask = bs_long( h11P->green_mask );
  1549. X        h11P->blue_mask = bs_long( h11P->blue_mask );
  1550. X        h11P->bits_per_rgb = bs_long( h11P->bits_per_rgb );
  1551. X        h11P->colormap_entries = bs_long( h11P->colormap_entries );
  1552. X        h11P->ncolors = bs_long( h11P->ncolors );
  1553. X        h11P->window_width = bs_long( h11P->window_width );
  1554. X        h11P->window_height = bs_long( h11P->window_height );
  1555. X        h11P->window_x = bs_long( h11P->window_x );
  1556. X        h11P->window_y = bs_long( h11P->window_y );
  1557. X        h11P->window_bdrwidth = bs_long( h11P->window_bdrwidth );
  1558. X        }
  1559. X        if ( fread( junk, h11P->header_size - sizeof(*h11P), 1, file ) != 1 )
  1560. X        {
  1561. X        fprintf( stderr, "Couldn't read rest of X11 XWD file header.\n" );
  1562. X        exit( 1 );
  1563. X        }
  1564. X        if ( fread( junk, sizeof(X11XColor), h11P->ncolors, file ) !=
  1565. X         h11P->ncolors )
  1566. X        {
  1567. X        fprintf( stderr, "Couldn't read X11 XWD colormap.\n" );
  1568. X        exit( 1 );
  1569. X        }
  1570. X
  1571. X        /* Check whether we can handle this dump. */
  1572. X        if ( h11P->pixmap_depth != 1 )
  1573. X        {
  1574. X        fprintf( stderr, "Can't handle X11 pixmap_depth != 1.\n" );
  1575. X        exit( 1 );
  1576. X        }
  1577. X        if ( h11P->pixmap_format != XYBitmap &&
  1578. X         h11P->pixmap_format != ZPixmap )
  1579. X        {
  1580. X        fprintf( stderr, "Can't handle X11 pixmap_format %d.\n",
  1581. X             h11P->pixmap_format );
  1582. X        exit( 1 );
  1583. X        }
  1584. X        if ( h11P->bitmap_unit != h11P->bitmap_pad )
  1585. X        {
  1586. X        fprintf(
  1587. X            stderr,
  1588. X            "X11 bitmap_unit (%d) != bitmap_pad (%d) - can't handle.\n",
  1589. X            h11P->bitmap_unit, h11P->bitmap_pad );
  1590. X        exit( 1 );
  1591. X        }
  1592. X        if ( h11P->bitmap_unit != 8 && h11P->bitmap_unit != 16 &&
  1593. X         h11P->bitmap_unit != 32 )
  1594. X        {
  1595. X        fprintf(
  1596. X            stderr,
  1597. X            "X11 bitmap_unit (%d) is non-standard - can't handle.\n",
  1598. X            h11P->bitmap_unit );
  1599. X        exit( 1 );
  1600. X        }
  1601. X
  1602. X        *colP = h11P->pixmap_width;
  1603. X        *rowP = h11P->pixmap_height;
  1604. X        *padrightP = h11P->bytes_per_line * 8 - h11P->pixmap_width;
  1605. X        bits_per_item = h11P->bitmap_unit;
  1606. X        bits_used = bits_per_item;
  1607. X        bit_order = h11P->bitmap_bit_order;
  1608. X        bit_invert = 0;
  1609. X        }
  1610. X    else
  1611. X        {
  1612. X        fprintf( stderr, "Unknown XWD file version: %d.\n",
  1613. X             h11P->file_version );
  1614. X        exit( 1 );
  1615. X        }
  1616. X    }
  1617. X
  1618. X    byteP = (char *) buf;
  1619. X    shortP = (short *) buf;
  1620. X    longP = (long *) buf;
  1621. X    }
  1622. X
  1623. Xbit
  1624. Xgetbit( file )
  1625. XFILE *file;
  1626. X    {
  1627. X    bit b;
  1628. X
  1629. X    if ( bits_used == bits_per_item )
  1630. X    {
  1631. X    if ( fread( buf, bits_per_item / 8, 1, file ) != 1 )
  1632. X        {
  1633. X        fprintf( stderr, "Couldn't read bits.\n" );
  1634. X        exit( 1 );
  1635. X        }
  1636. X    switch ( bits_per_item )
  1637. X        {
  1638. X        case 8:
  1639. X        break;
  1640. X
  1641. X        case 16:
  1642. X        if ( byte_swap )
  1643. X        *shortP = bs_short( *shortP );
  1644. X        break;
  1645. X
  1646. X        case 32:
  1647. X        if ( byte_swap )
  1648. X        *longP = bs_long( *longP );
  1649. X        break;
  1650. X        }
  1651. X    bits_used = 0;
  1652. X
  1653. X    if ( bit_order == MSBFirst )
  1654. X        bit_shift = bits_per_item - 1;
  1655. X    else
  1656. X        bit_shift = 0;
  1657. X    }
  1658. X
  1659. X    switch ( bits_per_item )
  1660. X    {
  1661. X    case 8:
  1662. X    b = ( *byteP >> bit_shift) & 1;
  1663. X    break;
  1664. X
  1665. X    case 16:
  1666. X    b = ( *shortP >> bit_shift) & 1;
  1667. X    break;
  1668. X
  1669. X    case 32:
  1670. X    b = ( *longP >> bit_shift) & 1;
  1671. X    break;
  1672. X    }
  1673. X
  1674. X    if ( bit_invert )
  1675. X    b = 1 - b;
  1676. X
  1677. X    if ( bit_order == MSBFirst )
  1678. X    bit_shift--;
  1679. X    else
  1680. X    bit_shift++;
  1681. X    bits_used++;
  1682. X
  1683. X    return b;
  1684. X    }
  1685. X
  1686. Xshort
  1687. Xbs_short( s )
  1688. Xshort s;
  1689. X    {
  1690. X    short ss;
  1691. X    unsigned char *bp, t;
  1692. X
  1693. X    ss = s;
  1694. X    bp = (unsigned char *) &ss;
  1695. X    t = bp[0];
  1696. X    bp[0] = bp[1];
  1697. X    bp[1] = t;
  1698. X    return ss;
  1699. X    }
  1700. X
  1701. Xint
  1702. Xbs_int( i )
  1703. Xint i;
  1704. X    {
  1705. X    int ii;
  1706. X    unsigned char *bp, t;
  1707. X
  1708. X    ii = i;
  1709. X    bp = (unsigned char *) ⅈ
  1710. X    t = bp[0];
  1711. X    bp[0] = bp[3];
  1712. X    bp[3] = t;
  1713. X    t = bp[1];
  1714. X    bp[1] = bp[2];
  1715. X    bp[2] = t;
  1716. X    return ii;
  1717. X    }
  1718. X
  1719. Xlong bs_long( l )
  1720. Xlong l;
  1721. X    {
  1722. X    return bs_int( l );
  1723. X    }
  1724. SHAR_EOF
  1725. if test 8899 -ne "`wc -c < 'xwdtopbm.c'`"
  1726. then
  1727.     echo shar: error transmitting "'xwdtopbm.c'" '(should have been 8899 characters)'
  1728. fi
  1729. fi # end of overwriting check
  1730. #    End of shell archive
  1731. exit 0
  1732.